import 'dart:math';

import 'package:flutter/material.dart';

class CommonData with ChangeNotifier {
  UserModel _userModel;

  changeUserModel() {
    UserModel userModel = UserModel();
    userModel.name = Random().nextInt(1000).toString();
    userModel.age = Random().nextInt(100);

    _userModel = userModel;
    notifyListeners();
  }

  changeUsername(String name) {
    _userModel.name = name;
    notifyListeners();
  }

  changeUserAge(int age) {
    _userModel.age = age;
    notifyListeners();
  }

  UserModel get userModel => _userModel;

  int get userAge => _userModel?.age ?? -1;

  String get userName => _userModel?.name ?? "-";
}

class UserModel {
  String name;
  int age;

  @override
  String toString() {
    return 'UserModel{name: $name, age: $age}';
  }
}
